package com.ruoyi.collect.engine.client;

import java.util.HashMap;
import java.util.Map;

/**
 * MacCMS API request parameters
 * Compatible with MacCMS API format
 *
 * @author ruoyi
 * @date 2025-11-07
 */
public class MacCmsRequest {

    /** Action: list=list, detail=detail */
    private String ac = "list";

    /** Page number */
    private Integer pg = 1;

    /** Type ID */
    private Integer t;

    /** Hours for recent data */
    private Integer h;

    /** Video IDs (comma separated) */
    private String ids;

    /** Search keyword */
    private String wd;

    /** Parameters (base64) */
    private String param;

    /** Page size */
    private Integer pagesize;

    /** Order by field */
    private String order;

    /** Extension parameters */
    private Map<String, Object> extParams = new HashMap<>();

    /**
     * Build URL query string
     */
    public String toQueryString() {
        StringBuilder sb = new StringBuilder();
        sb.append("?ac=").append(ac != null ? ac : "list");

        if (pg != null) {
            sb.append("&pg=").append(pg);
        }
        if (t != null) {
            sb.append("&t=").append(t);
        }
        if (h != null) {
            sb.append("&h=").append(h);
        }
        if (ids != null && !ids.isEmpty()) {
            sb.append("&ids=").append(ids);
        }
        if (wd != null && !wd.isEmpty()) {
            sb.append("&wd=").append(wd);
        }
        if (param != null && !param.isEmpty()) {
            sb.append("&param=").append(param);
        }
        if (pagesize != null) {
            sb.append("&pagesize=").append(pagesize);
        }
        if (order != null && !order.isEmpty()) {
            sb.append("&order=").append(order);
        }

        // Add extension parameters
        for (Map.Entry<String, Object> entry : extParams.entrySet()) {
            sb.append("&").append(entry.getKey()).append("=").append(entry.getValue());
        }

        return sb.toString();
    }

    // Getters and setters
    public String getAc() {
        return ac;
    }

    public void setAc(String ac) {
        this.ac = ac;
    }

    public Integer getPg() {
        return pg;
    }

    public void setPg(Integer pg) {
        this.pg = pg;
    }

    public Integer getT() {
        return t;
    }

    public void setT(Integer t) {
        this.t = t;
    }

    public Integer getH() {
        return h;
    }

    public void setH(Integer h) {
        this.h = h;
    }

    public String getIds() {
        return ids;
    }

    public void setIds(String ids) {
        this.ids = ids;
    }

    public String getWd() {
        return wd;
    }

    public void setWd(String wd) {
        this.wd = wd;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public Integer getPagesize() {
        return pagesize;
    }

    public void setPagesize(Integer pagesize) {
        this.pagesize = pagesize;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public Map<String, Object> getExtParams() {
        return extParams;
    }

    public void setExtParams(Map<String, Object> extParams) {
        this.extParams = extParams;
    }

    public void addExtParam(String key, Object value) {
        this.extParams.put(key, value);
    }
}